<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>车辆事故</title>
    <link rel="stylesheet" href="UC_style.css">
    <style>
        .main {
            width: 100%;
            height: 800px;
            background: RGB(239,239,239);
            float: left;
        }

        #header2 {
            height: 40px;
            background: white;
        }

        table,
        th,
        td {
            background-color: white;
            border: 1px solid black;
            border-collapse: collapse;
        }

        td {
            width: 200px;
            height: 50px;
            padding: 5px;
        }

        th {
            font-size: 18px;
        }

        .had {
            text-align: center;
            height: 600px;
            width: 80%;
            margin: 0px auto;
        }

        .input1 {
            border: 0px;
            height: 90%;
            font-size:16px;
            width: 100%;
        }
        .text {
            border: none;
            height: 50px;
            width: 100%;
            font-size: 16px;
        }
        select {
            border: 0px;
            height: 90%;
            width: 90%;
        }

        textarea {
            border: 0px;
            width: 100%;
            resize: none;
            font-size: 16px;
        }

        .button1 {
            height: 40px;
            width: 120px;
            font-size: 15px;
            margin-left: 1000px;
            position: center;
            color: #000000;
            background-color: #808080;
        }

        h2 {
            text-align: center;
        }
        .input2 {
            color: black;
            background-color: RGB(239,239,239);
            font-size: 20px;
            height: 40px;
            width: 100px;
            margin-left: 450px;
            margin-right: 30px;
        }

            .input2:hover {
                background-color: #808080;
            }
        .button_file {
            background-color: white;
            color: RGB(64,158,255);
            height: 22px;
            text-align: center;
            font-size: 16px;
            border: none;
            font-weight: bold;
        }

            .button_file:hover {
                background-color: RGB(249,249,249);
            }

            .button_file:active {
                transform: translateY(2px);
            }
   .buttons {
	margin-left: 230px;
	margin-top: 30px;
	text-align: center;
		}
		button {
	padding: 10px 20px;
	margin-right: 200px;
	border-radius: 5px;
	border: none;
	background-color: white;
	color: black;
	cursor: pointer;
	transition: all 0.3s ease;
}

button:hover {
	background-color: #333;
}
button:last-child {
	background-color: #2196F3;
}

button:last-child:hover {
	background-color: #0069c0;
}

    </style>
</head>

<body>
<%
	String id=request.getParameter("id");//取得传递过来的用户参数，用于查询和删除
	Connection conn=null;
	String sql="select * from TrafficViolation  where id='"+id+"'";
	try{
		Class.forName("org.h2.Driver");//加载驱动
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
		return;
	}
	try {
		conn = DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
		Statement stmt = conn.createStatement();
		ResultSet rs = stmt.executeQuery(sql);
		if(rs!=null && rs.next()){//执行完sql语句后，rs指向第一条结果的前面，所以必须执行一次next()操作
			System.out.println("right");
		}
		else
		{	
			System.out.println("null");
		}
%>
    <div class="main">
        <div id="header2">
            <img src="img/frist.png" alt="Big Boat" width="30" height="30" style=" vertical-align: middle;">
            司机端 > 车辆事故
        </div>
        <h2>事故申报表</h2>
        <%String editURL="D-jdbc-Details_Violation_edit.jsp?action=2&id="+rs.getInt("id"); %>
        <form id="form1" action=<%=editURL %> method="post">
            <table class="had">
                <thead>
                    <tr>
                        <th>报告人：</th>
                        <td><input class="input1" name="reporter" type="text" readonly value=<%= rs.getString("reporter") %>></td>
                        <th>联系电话：</th>
                        <td>
                            <input class="input1" name="phone_number" type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" value=<%= rs.getString("phone_number") %>>
                        </td>
                        <th>事故时间：</th>
                        <td><input class="input1" name="accident_time" type="datetime-local" id="date" name="date"  value=<%= rs.getString("accident_time") %>></td>
                    </tr>
                    </thead>
                <tbody>
                    <tr>
                        <th>车牌：</th>
                        <td>
                            <input class="input1" name="license_plate" type="text" readonly value=<%= rs.getString("license_plate") %>>
                        </td>
                        <th>违章类别：</th>
                        <td>
                        <input class="input1" name="violation_type" type="text" list="violation_type"  value=<%= rs.getString("violation_type") %>>                       
                            <datalist id="violation_type" >
                                <option value="闯红灯">闯红灯</option>
                    			<option value="超速">超速</option>
                    			<option value="超载">超载</option>
                    			<option value="违章停车">违章停车</option>
                    			<option value="无证驾驶">无证驾驶</option>
                    			<option value="违章超车">违章超车</option>
                   			 	<option value="疲劳驾驶">疲劳驾驶</option>
                    			<option value="酒后驾驶">酒后驾驶</option>
                    			<option value="未系安全带">未系安全带</option>
                    			<option value="车祸">车祸</option>
                            </datalist>
                        </td>
                        <th>扣分：</th>
                        <td><input class="input1" type="number" id="" name="penalty_points" min="1" max="12"  value=<%= rs.getString("penalty_points") %>></td>
                    </tr>
                    <tr>
                        <th>车辆状况：</th>
                        <td>
                        <input class="input1" name="vehicle_condition" type="text" list="vehicle_condition"  value=<%= rs.getString("vehicle_condition") %>> 
                            <datalist id="vehicle_condition">
                                <option value="可行驶">可行驶</option>
                                <option value="不可行驶">不可行驶</option>
                                <option value="报废">报废</option>
                            </datalist>
                        </td>
                        <th>事故地点：</th>
                        <td><input class="input1" name="accident_location" type="text"  value=<%= rs.getString("accident_location") %>></td>
                        <th>赔偿金额：</th>
                        <td><input class="input1" name="compensation" type="text" value=<%= rs.getString("compensation") %> onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d.]/g,'')"></td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <th style="height:100px">事故描述：</th>
                        <td colspan="5"><input style="border: 0px;width:100%; height:200px;" id="reason" value=<%= rs.getString("accident_description") %> name="accident_description"  ></td>
                    </tr>
                    <tr>
                        <th style="height:100px">备注：</th>
                        <td colspan="5"><input style="border: 0px;width:100%;height:150px;" id="reason1" value=<%= rs.getString("remarks") %> name="remarks"  ></td>
                    </tr>
                    <tr>
                        <th style="height:50px">附件</th>
                        <td colspan="5" style="text-align:left">
                            <input type="button" class="button_file" value="添加附件" onclick="path.click()">
                            <input type="text" class="text" name="lookfile" id="lookfile" style="outline:none;" readonly>
                            <input type="file" id="path" name="attachment" style="display:none" onchange="lookfile.value+='   '+this.value">
                        </td>
                    </tr>
                </tfoot>
            </table>
<%
				rs.close();
				stmt.close();
				//关闭表达式对象				
				conn.close();

				} catch (SQLException e) {
					e.printStackTrace();
				} finally {
				//防止数据库未正常关闭
					try {
						if (conn != null && (!conn.isClosed())) {
							conn.close();
					}
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
		%>
            <div class="buttons">
            <button type="submit">提交</button>
			<button type="button" onclick="history.back()">返回</button>
		</div>
        </form>
    </div>
</body>
</html>
